package View;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import View.Components.TouchButton;
import View.Components.TouchObjectContainer;

public class ControllPlayer extends JPanel implements TouchObjectContainer, ActionListener{
	private static final long serialVersionUID = 3492271746922860779L;
	public MainWindow _unnamed_Window_;
	private PlayList playlist;
	private TouchButton tPlay, tStop, tSkip, tBack;

	public ControllPlayer(MainWindow mw){
		super();
		_unnamed_Window_ = mw;
		this.setBackground(Color.red);
		setupButtons();
		setupGUI();
	}
	
	public void setupGUI(){
		this.setLayout(new FlowLayout());
		this.add(tBack);
		this.add(tPlay);
		this.add(tStop);
		this.add(tSkip);
	}
	
	public void setupButtons() {
		ImageIcon icNormal = new ImageIcon(
		ClassLoader.getSystemResource("test_kevin/Play.png"));
		ImageIcon icPressed = new ImageIcon(
		ClassLoader.getSystemResource("test_kevin/PlayPressed.png"));
		ImageIcon icLeft = new ImageIcon(
		ClassLoader.getSystemResource("test_kevin/PlayLeft.png"));

		tBack = new TouchButton("Back");
		tBack.addActionListener(this);
		
		tPlay = new TouchButton("Play");
		tPlay.addActionListener(this);
		tPlay.setPreferredSize(new Dimension(80,80));
		
		tStop = new TouchButton("Stop");
		tStop.addActionListener(this);
		tStop.setPreferredSize(new Dimension(80,80));
		
		tSkip = new TouchButton("Skip");
		tSkip.addActionListener(this);
	}
	
	/**
	 * This method returns the variable playlist.
	 * @return the playlist
	 */
	public PlayList getPlaylist() {
		return playlist;
	}

	/**
	 * This method sets the variable playlist.
	 * @param playlist the playlist to set
	 */
	public void setPlaylist(PlayList playlist) {
		this.playlist = playlist;
	}

	/**
     * This method return the variable mother.
     * @return the mother
     */
    public MainWindow getMother() {
        return mother;
    }

    /**
     * This methods sets the variable mother.
     * @param mother the mother to set
     */
    public void setMother(MainWindow mother) {
        this.mother = mother;
    }

    private MainWindow mother;
    @Override
    public void actionPerformed(ActionEvent ev) {
        try{
            if(mother.getPlaylist().getPlayer() != null){
                if(ev.getActionCommand().equals("Skip"))
                    mother.getPlaylist().getPlayer().next();
                if(ev.getActionCommand().equals("Play"))
                    mother.getPlaylist().getPlayer().play();
                if(ev.getActionCommand().equals("Stop"))
                    mother.getPlaylist().getPlayer().stop();
                if(ev.getActionCommand().equals("Back"))
                    mother.getPlaylist().getPlayer().back();
        }
        }catch(Exception e){
            
        }
    }
	
	
}